﻿using UnityEditor;
using UnityEngine;

namespace HK.Editor.GUIEx.Protocol.Drag
{

    /// <summary>
    /// 接口 : 拖拽元素
    /// </summary>
    public interface IDragElement
    {
        /// <summary>
        /// Property
        /// </summary>
        SerializedProperty Property { get; set; }
        
        /// <summary>
        /// 开始索引
        /// </summary>
        int StartIndex { get; set; }
			
        /// <summary>
        /// 拖拽偏移
        /// </summary>
        float DragOffset { get; set; }
			
        /// <summary>
        /// 选中标志位
        /// </summary>
        bool Selected { get; set; }
			
        /// <summary>
        /// 矩形区域
        /// </summary>
        Rect Rect { get; set; }
        
        /// <summary>
        /// 希望拖拽区域
        /// </summary>
        Rect DesiredRect { get; set; }

        /// <summary>
        /// 重叠校验
        /// </summary>
        /// <param name="iCurRect">当前矩形区域</param>
        /// <param name="iIndex">索引</param>
        /// <param name="iDirection"></param>
        /// <returns>true:重叠; false:不重叠;</returns>
        bool Overlaps(Rect iCurRect, int iIndex, int iDirection);

        /// <summary>
        /// 记录/采样 拖拽元素列表状态
        /// </summary>
        void RecordState();

        /// <summary>
        /// 恢复状态
        /// </summary>
        /// <param name="iProperty">Property</param>
        void RestoreState(SerializedProperty iProperty);
    }
    
    /// <summary>
    /// 接口 : 列表拖拽区域
    /// </summary>
    public interface IDragRectsList
    {
        /// <summary>
        /// 开始索引
        /// </summary>
        int StartIndex { get; }
        
        /// <summary>
        /// 长度
        /// </summary>
        int Length { get; }
        
        /// <summary>
        /// 拖拽Element列表
        /// </summary>
        IDragElement[] Elements { get; }
        
        /// <summary>
        /// 下表
        /// </summary>
        /// <param name="iIndex">索引</param>
        IDragElement this[int iIndex] { get; set; }

        /// <summary>
        /// 重置尺寸
        /// </summary>
        /// <param name="iStart">开始索引</param>
        /// <param name="iLength">长度</param>
        void Resize(int iStart, int iLength);

        /// <summary>
        /// 根据索引排序
        /// </summary>
        void SortByIndex();

        /// <summary>
        /// 记录/采样 拖拽元素列表状态
        /// </summary>
        void RecordState();

        /// <summary>
        /// 回复列表状态
        /// </summary>
        /// <param name="iList">列表</param>
        void RestoreState(SerializedProperty iList);

        /// <summary>
        /// 根据位置排序
        /// </summary>
        void SortByPosition();

        int GetIndexFromSelection(int iIndex);
    }
}
